package com.cykj.finance.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.cykj.common.core.utils.poi.ExcelUtil;
import com.cykj.common.core.web.controller.BaseController;
import com.cykj.common.core.web.domain.AjaxResult;
import com.cykj.common.core.web.page.TableDataInfo;
import com.cykj.common.log.annotation.Log;
import com.cykj.common.log.enums.BusinessType;
import com.cykj.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cykj.finance.domain.FnLevelCommission;
import com.cykj.finance.service.IFnLevelCommissionService;


/**
 * 等级佣金Controller
 *
 * @author 天才少年
 * @date 2025-08-19
 */
@RestController
@RequestMapping("/level")
public class FnLevelCommissionController extends BaseController {
    @Autowired
    private IFnLevelCommissionService fnLevelCommissionService;

    /**
     * 查询等级佣金列表
     */
    @RequiresPermissions("finance:level:list")
    @GetMapping("/list")
    public TableDataInfo list(FnLevelCommission fnLevelCommission) {
        startPage();
        List<FnLevelCommission> list = fnLevelCommissionService.selectFnLevelCommissionList(fnLevelCommission);
        return getDataTable(list);
    }

    /**
     * 导出等级佣金列表
     */
    @RequiresPermissions("finance:level:export")
    @Log(title = "等级佣金", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FnLevelCommission fnLevelCommission) {
        List<FnLevelCommission> list = fnLevelCommissionService.selectFnLevelCommissionList(fnLevelCommission);
        ExcelUtil<FnLevelCommission> util = new ExcelUtil<FnLevelCommission>(FnLevelCommission.class);
        util.exportExcel(response, list, "等级佣金数据");
    }

    /**
     * 获取等级佣金详细信息
     */
    @RequiresPermissions("finance:level:query")
    @GetMapping(value = "/{levelId}")
    public AjaxResult getInfo(@PathVariable("levelId") Long levelId) {
        return success(fnLevelCommissionService.selectFnLevelCommissionByLevelId(levelId));
    }

    /**
     * 新增等级佣金
     */
    @RequiresPermissions("finance:level:add")
    @Log(title = "等级佣金", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FnLevelCommission fnLevelCommission) {
        return toAjax(fnLevelCommissionService.insertFnLevelCommission(fnLevelCommission));
    }

    /**
     * 修改等级佣金
     */
    @RequiresPermissions("finance:level:edit")
    @Log(title = "等级佣金", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FnLevelCommission fnLevelCommission) {

        System.out.println("接收的数据: " + fnLevelCommission);


        return toAjax(fnLevelCommissionService.updateFnLevelCommission(fnLevelCommission));
    }

    /**
     * 删除等级佣金
     */
    @RequiresPermissions("finance:level:remove")
    @Log(title = "等级佣金", businessType = BusinessType.DELETE)
    @DeleteMapping("/{levelIds}")
    public AjaxResult remove(@PathVariable Long[] levelIds) {
        return toAjax(fnLevelCommissionService.deleteFnLevelCommissionByLevelIds(levelIds));
    }
}
